package com.momo.elasticsearch;

import com.momo.elasticsearch.entity.EcDataLogDO;
import com.momo.elasticsearch.entity.EcMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by MOMO on 2019/3/12.
 */
@Service
public class AsyncService {
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    SnowFlake snowFlake = new SnowFlake(1, 1);
    @Autowired
    private EcMapper ecMapper;

    @Async("threadPoolTaskExecutor")
    public void test(Integer i) {
        List<EcDataLogDO> ecDataLogDOS = ecMapper.all(10, i * 10);
        ecDataLogDOS.forEach(ecDataLogDO1 -> {
            if (null != ecDataLogDO1) {
                ecDataLogDO1.setLongid(snowFlake.nextId());
                elasticsearchUtil.addOneDocument("sys_core_v1", "d_ec_data_log", String.valueOf(snowFlake.nextId()), ecDataLogDO1);
            }//
        });
    }
}
